package me.idashu.attg.aop;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ControllerSelectorInterceptor {
	
	@Before("execution(* me.idashu.attg..*.*Controller.*Do(..,javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse))")
    public void doBefore(JoinPoint jp) {
		Object[] args = jp.getArgs();
		HttpServletRequest request = (HttpServletRequest) args[args.length-2];
		request.setAttribute("aop", "ok");
		System.out.println("before");
    }

	 @After("execution(* me.idashu.attg..*.*Controller.*Do(..,javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse))")
	 public void doAfter(JoinPoint jp) {  
		Object[] args = jp.getArgs();
		HttpServletRequest request = (HttpServletRequest) args[args.length-2];
		String aop = (String) request.getAttribute("aop");
		System.out.println("after "+aop);
	 }
}